<template>
  <div class="line"></div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  data () {
    return {

      option: {
        title: {
          text: '',
          textStyle: {
            color: 'blue'
          }
        },
        backgroundColor: '#020347',
        legend: {

        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        xAxis: {
          type: 'category',
          data: ['01日', '02日', '03日', '04日', '05日', '06日', '07日', '08日', '09日', '10日', '11日', '12日', '13日', '14日', '15日', '16日']
        },
        // y轴配置
        yAxis: {
          type: 'value'

        },
        series: [
          {
            type: 'line',
            name: 'B',
            data: ['0', '1', '0'],
            areaStyle: {
              color: {
                // 渐变
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [{
                  offset: 0, color: 'green' // 0% 处的颜色
                }, {
                  offset: 1, color: 'blue' // 100% 处的颜色
                }],
                global: false
              }
            }

            // colorStops: [{
            //   offset: 0, color: 'red'// 0% 处的颜色
            // }, {
            //   offset: 1, color: 'pink' // 100% 处的颜色
            // }]
          },
          {
            type: 'line',
            name: 'A',
            data: ['0', '0', '0', '0', '1', '0'],
            // 区域颜色
            areaStyle: {
              color: {

                type: 'linear',
                x: 0,
                y: 0,
                x2: 1,
                y2: 1,
                colorStops: [{
                  offset: 0, color: 'red' // 0% 处的颜色
                }, {
                  offset: 1, color: 'blue' // 100% 处的颜色
                }]

              }
            }
          }
        ]
      }
    }
  },

  methods: {
    line () {
      const echartsline = echarts.init(document.querySelector('.line'))
      echartsline.setOption(this.option)
    }
  },
  mounted () {
    this.line()
  },
  watch: {
    '$store.state.one': function (newval, oldval) {
      // console.log(newval, '侦听vuex的newval')
      // console.log(oldval, '侦听vuex的oldval')
      this.option.title.text = newval
      // console.log(val, '11')
      this.line()
    }

  }
}
</script>

<style>
.line{
  display: flex;
  flex:4;
/* width: 1000px; */
height: 400px;
/* background-color: yellow; */
}
</style>
